﻿using System.Text.RegularExpressions;
using PaceR.Core.Interfaces.PatternMatching;

namespace PaceR.Core.PatternMatching
{
    public class RegexPatternMatcher : IPatternMatcher<string>
    {
        public RegexPatternMatcher()
            : this(string.Empty)
        { }

        public RegexPatternMatcher(string pattern)
        {
            Pattern = pattern;
        }

        #region IPatternMatcher<string> Members

        public virtual string Pattern { get; set; }

        public virtual bool Match(string testParam)
        {
            if (!string.IsNullOrEmpty(Pattern) && !string.IsNullOrEmpty(testParam))
            {
                Regex m = new Regex(Pattern);
                return m.IsMatch(testParam);
            }
            return false;
        }

        #endregion
    }
}
